﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConnectionControl;
using LSProtocol;
using pokerServer.ProtHandlers;

namespace pokerServer.ProtHandlers
{
	class regProtHandle : absRegAutHandle
	{
		public regProtHandle(String[] synt, ClientConnection cc)
		{
			this.mstrings = synt;
			base.stringSort(synt);
			this.dbc = cc.getDBC();
		}

		public override String work()
		{
			dbc.OpenConnection();
			sup = new SignUpProtocol(dbc);			
			er = sup.signUp(mstrings[0], mstrings[1]);
			String ans = "";
			switch (er)
			{
				case Errors.ERR_UsernameIsTaken:
					ans = "REGISTER-FAIL UsernameTaken";
					break;
				case Errors.ERR_UsernameRegistered:
					ans = "REGISTER-ACK Registered";
					break;
				case Errors.ERR_PassTooShort:
					ans = "REGISTER-FAIL PasswordTooShort";
					break;
				case Errors.ERR_UsernameIlChars:
					ans = "REGISTER-FAIL UserWithIleagalChars!";
					break;
				case Errors.ERR_PassIlChars:
					ans = "REGISTER-FAIL PassIleagalChars!";
					break;
				case Errors.ERR_UsernameToolong:
					ans = "REGISTER-FAIL UsernameTooLong";
					break;
				case Errors.ERR_UsernameTooShort:
					ans = "REGISTER-FAIL UsernameTooShort";
					break;
			
			}
			dbc.closeConnection();
			return ans;
		}
	}
}
